
import axios from '@ohos/axios'
import Account from '../viewModel/Account'
import AccountType from '../viewModel/AccountType'
import Budget from '../viewModel/Budget'
import User from '../viewModel/User'
// let baseUrl= '10.2.2.108'
let baseUrl= '192.168.43.254'
class BudgetModel{
  //查询
  getBudgetList(date:string):Promise<Budget[]>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'GET',
        // url:'http://localhost:8080/budget/showBudget',
        url:'http://'+baseUrl+':8080/budget/showBudget',
        params:{
          date:date,
          uid:AppStorage.Get('uid')
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('查询失败')
      })
    })
  }
  //新增
  insertBudget(budget:Budget):Promise<number>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'POST',
        // url:'http://localhost:8080/budget/insertBudget',
        url:'http://'+baseUrl+':8080/budget/insertBudget',
        data:{
          uid:budget.uid,
          isdelete:0,
          price:budget.price,
          date:budget.date
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('失败')
      })
    })
  }

  //修改
  updateRecord(budget:Budget):Promise<number>{
    console.log('model,price: ',budget.price)
    return new Promise((resolve,reject)=>{
      axios({
        method:'POST',
        // url:'http://localhost:8080/budget/updateBudget',
        url:'http://'+baseUrl+':8080/budget/updateBudget',
        data:{
          bid:budget.bid,
          price:budget.price,
          isdelete:0,
          uid:budget.uid,
          date:budget.date
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('失败')
      })
    })
  }


}
const budgetModel = new BudgetModel();
export default budgetModel as BudgetModel;


